<?php
//返回文章列表，next是否包括下级栏目的文章
function getCateArt($id,$limit=8,$next = 0,$thumb = 0){
    $listid[] = $id;
    if($next == 1){
        $listid = findArtNextKind($id,$listid);
    }
    $where = "is_hide=0";
    $where .= " and kind_id in (".implode(',',$listid).")";

    if($thumb == 1){
        $where .= " thumb<>''";
    }
    $article_lists = Db::name("article")->where($where)->order("sort_order,add_time desc")->limit($limit)->select();
    // if ($article_lists) {
    //     foreach ($article_lists as $key => $value) {
    //         $article_lists[$key]['nav_link'] = U('Index/article',array('id'=>$value['article_id']));
    //     }
    // }
    return $article_lists;
}
//获取底部文章
function getFootArt($id,$limit=8,$next = 0,$thumb = 0){
    $listid[] = $id;
    if($next == 1){
        $listid = findArtNextKind($id,$listid);
    }
    $where = "is_hide=0 and is_tj=1";
    $where .= " and kind_id in (".implode(',',$listid).")";

    if($thumb == 1){
        $where .= " thumb<>''";
    }
    $article_lists = Db::name("article")->where($where)->order("sort_order,add_time desc")->limit($limit)->select();
    // if ($article_lists) {
    //     foreach ($article_lists as $key => $value) {
    //         $article_lists[$key]['nav_link'] = U('Index/article',array('id'=>$value['article_id']));
    //     }
    // }
    return $article_lists;
}
function findArtNextKind($id,$list){
    // $list = array();
    $data = Db::name('articleKind')->where(array('parent_id'=>$id,'is_hide'=>0))->select();
    if ($data) {
        foreach ($list as $key => $value) {
            foreach ($data as $ke => $val) {
                $list[] = $val['kind_id'];
                $list = findArtNextKind($val['kind_id'],$list);
            }
        }
        $return = array_unique($list);
    } else {
        $return = array_unique($list);
    }
    return $return;
}
function findProNextKind($id,$list){
    // $list = array();
    $data = Db::name('productKind')->where(array('parent_id'=>$id,'is_hide'=>0))->select();
    if ($data) {
        foreach ($list as $key => $value) {
            foreach ($data as $ke => $val) {
                $list[] = $val['kind_id'];
                $list = findProNextKind($val['kind_id'],$list);
            }
        }
        $return = array_unique($list);
    } else {
        $return = array_unique($list);
    }
    return $return;
}


function return_json($data) {
    //  header ( 'Content-Type:application/json; charset=utf-8' );
    exit ( json_encode ( $data ) );
}




?>